<template>
  <div id="balance">
    <c-title :hide="false" text="提货积分"></c-title>
    <diyBackGround></diyBackGround>
    <div class="main">
      <div class="topMy">
        <div class="left">
          <div class="txt">提货积分</div>
          <div class="priceNum">
            {{ integralNumber }}
            <img src="https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/images%2Fintegral%2Fimage1.png" alt="" />
          </div>
        </div>
      </div>
      <div class="integralList" v-if="dataList.length > 0">
        <div class="title">
          <div class="title_left">提货积分列表</div>
        </div>
        <div class="integralLis" v-for="item in dataList" :key="item">
          <div class="top">
            <div class="txt">{{ item.remarks }}</div>
            <div class="priceNow"><template v-if="item.change_number > 0">+</template>{{ item.change_number }}</div>
          </div>
          <div class="bottom">
            <div class="time">{{ item.created_at }}</div>
            <div class="integralTotal">积分{{ item.old_number }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import diyBackGround from "../balance/componet/diyBackGround.vue";
import { scrollMixin } from "utils/mixin";
export default {
  components: { diyBackGround },
  mixins: [scrollMixin], //加载更多
  data() {
    return {
      integralNumber: 0,
      dataList: [],
      //more
      isLoadMore: true,
      page: 1,
      total_page: 0,
    };
  },
  activated() {
    this.getIntegral();
    this.getDataList();
  },
  methods: {
    /**
     * 获取积分数据
     */
    getIntegral() {
      var that = this;
      $http
        .get(
          "plugin.integral.Frontend.Controllers.Page.getintegral",
          {
            i: this.fun.getKeyByI(),
            type: this.fun.getTyep()
          },
          "加载中"
        ).then(function(response) {
          // if (response.result == 1) {
          //   that.integralNumber = response.data.integral_number
          // }
          that.integralNumber = response.integral;
        },function (response) {
          that.$dialog.alert({ message: response.msg });
        });
    },

    /**
     * 获取积分列表
     */
    getDataList() {
      $http.post("plugin.devote.frontend.index.get-log", { page: this.page }, ' ').then(res => {
        if (res.result) {
          const { list, size, total } = res.data;
          this.dataList = list;
          this.isLoadMore = true;
          this.total_page = Math.ceil(total/size);
          if (!this.total_page) {
            this.total_page = 0;
          }
        } else {
          this.$dialog.alert({ message: res.msg });
        }
      });
    },

    /**
     * 积分类标上拉加载更多
     */
    getMoreData() {
      if (!this.isLoadMore) return;
      this.isLoadMore = false; // 防止多次请求分页数据
      if (this.page >= this.total_page) {
        return;
      } else {
        this.page += 1;
        $http.post("plugin.devote.frontend.index.get-log", { page: this.page }).then(response => {
          if (response.result === 1) {
            var nextPageData = response.data.list;
            this.dataList = this.dataList.concat(nextPageData);
            this.isLoadMore = true;
          } else {
            this.page = this.page - 1;
            this.isLoadMore = false;
          }
        });
      }
    },
  }
};
</script>

<style lang="scss" rel="stylesheet/scss" scoped>
#balance {
  .main {
    padding: 0 0.625rem;
    margin-top: -8rem;
    padding-bottom: 1rem;

    .integralList {
      margin-top: 0.5rem;
      padding: 1rem;
      border-radius: 0.625rem;
      background: #fff;

      .integralLis {
        display: flex;
        flex-direction: column;
        padding-bottom: 1rem;

        .top,
        .bottom {
          flex: 1;
          display: flex;
          justify-content: space-between;
          align-items: center;
        }

        .txt {
          font-weight: 500;
          color: #333;
          font-size: 0.8125rem;
        }

        .priceNow {
          font-size: 0.875rem;
          color: #f20606;
        }

        .priceNowAd {
          font-size: 0.875rem;
          color: #259b24;
        }

        .time,
        .integralTotal {
          font-size: 0.75rem;
          color: #999;
          font-weight: 400;
        }

        .top {
          margin-bottom: 0.5rem;
        }
      }

      .integralLis:last-child {
        padding-bottom: 0;
      }

      .title {
        display: flex;
        justify-content: space-between;
        margin-bottom: 1rem;

        .title_left {
          font-size: 1rem;
          font-weight: bold;
          color: #333;
        }

        .title_Right {
          display: flex;
          font-weight: 400;
          font-size: 0.6875rem;
          align-items: center;
          color: #878787;
        }
      }
    }

    .topMy {
      height: 5.125rem;
      background: #fff;
      border-radius: 0.625rem;
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 0 1rem;

      .right {
        width: 5.5rem;
        height: 2.125rem;
        background: var(--themeBaseColor);
        border-radius: 0.3125rem;
        text-align: center;
        line-height: 2.125rem;
        font-size: 0.75rem;
        color: #fff;
      }

      .left {
        text-align: left;

        .txt {
          font-size: 0.75rem;
          color: #666;
        }

        .priceNum {
          display: flex;
          font-size: 1.5rem;

          img {
            margin-bottom: 0.25rem;
            margin-left: 0.25rem;
            width: 1rem;
            height: 1rem;
          }
        }
      }
    }
  }
}
</style>
